package com.zac.coroutine.algorithm.leetcode.linkedlist

import com.zac.coroutine.algorithm.leetcode.linkedlist.IntersectionNode

/**
 * author zac
 * date 2025/8/1
 *
 */
object RemoveElements {
    @JvmStatic
    fun main(args: Array<String>) {

    }

    fun removeElements(head: IntersectionNode.ListNode?, `val`: Int): IntersectionNode.ListNode? {
        if (head == null) return null
        var realHead = head

        while (realHead?.`val` == `val`) {
            realHead = realHead.next
        }

        var a = realHead
        while (a != null) {
            if (a.next?.`val` == `val`) {
                a.next = a.next?.next
            } else {
                a = a.next
            }
        }
        return realHead

    }

}